<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017-08-14
 * Time: 0:35
 */

namespace app\api\model;

use think\Model;

class VcodeModel extends Model
{
    // 确定链接表名
    protected $table = 'xl_vcode';
    public function addVcode($mobile)
    {
        $ins_data = array();
        $ins_data['vcode'] = rand(1000, 9999);
        $ins_data['mobile'] = $mobile;
        $ins_data['create_time'] = $ins_data['update_time'] = time();
        if ($this->save($ins_data)) {
            return array("vcode" => $ins_data['vcode'], "mobile" => $mobile);
        } else {
            return false;
        }

    }

//验证
    public function checkAvailable($mobile, $vcode)
    {
        $time = time() - 600;
        $row = $this->where(array('vcode'=>$vcode,'mobile'=>$mobile))->find();
        if ($row) {
            if ($row['create_time'] >= $time) return 1;
            else return -1;
        } else {
            return 0;
        }
    }

}